13. Aspect Oriented Programming (AOP)
Aspect Oriented Programming (AOP)
In this lesson, you'll learn the basic concepts of AOP, and we'll cover how AOP frameworks use dynamic proxies and dependency injection.
ND079 JPND C2 L04 A12 Aspect Oriented Programming AOP
What is Aspect Oriented Programming?
Aspect Oriented Programming (AOP) is a design pattern that organizes code into cross-cutting concerns.
- A cross-cutting concern is any concern that affects many different parts of the system. Examples include: logging, performance profiling, and database transaction managements.
- All the code that handles a cross-cutting concern is organized into an aspect, which is subdivided into advice.
- Advice plugs into your executing code, via a method interceptor, to take care of the cross-cutting concern.
- Join points are places where advice can plug into your code, usually via method interceptors.
- Whereas a join point is a place where your code could potentially use advice, pointcuts are places where your code actually does use advice. An aspect is defined by advice and one or more pointcuts.
QUIZ QUESTION::
Match each AOP concept to its description.
ANSWER CHOICES:
AOP Concept |
Description |
---|---|
Cross-cutting concern |
|
Aspect |
|
Advice |
|
Join Point |
|
Pointcut |
SOLUTION:
AOP Concept |
Description |
---|---|
Pointcut |
|
Aspect |
|
Cross-cutting concern |
|
Join Point |
|
Advice |
How AOP Uses Dynamic Proxies and Dependency Injection
AOP uses dynamic proxies to intercept methods and execute advice.
When you add an
@Inject
annotation to your code, the AOP framework uses dependency injection to supply an object. The supplied object is actually a dynamic proxy with method interceptors to run different pieces of advice code.
SOLUTION:
- Instance method invocations
- Object creation
- Object destruction